home *** CD-ROM | disk | FTP | other *** search
/ InterCD 2000 September / september_2000.iso / intercd / root / ^Linux / WindowMaker / WPrefs.app / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-12  |  4.2 KB  |  203 lines

  1. /*
  2.  *  WPrefs - Window Maker Preferences Program
  3.  * 
  4.  *  Copyright (c) 1998 Alfredo K. Kojima
  5.  * 
  6.  *  This program is free software; you can redistribute it and/or modify
  7.  *  it under the terms of the GNU General Public License as published by
  8.  *  the Free Software Foundation; either version 2 of the License, or
  9.  *  (at your option) any later version.
  10.  *
  11.  *  This program is distributed in the hope that it will be useful,
  12.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  *  GNU General Public License for more details.
  15.  *
  16.  *  You should have received a copy of the GNU General Public License
  17.  *  along with this program; if not, write to the Free Software
  18.  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 
  19.  *  USA.
  20.  */
  21.  
  22. #include "WPrefs.h"
  23.  
  24.  
  25. #include <assert.h>
  26.  
  27. #include <X11/Xlocale.h>
  28.  
  29. #include <sys/wait.h>
  30. #include <unistd.h>
  31.  
  32.  
  33. char *NOptionValueChanged = "NOptionValueChanged";
  34.  
  35. extern void Initialize(WMScreen *scr);
  36.  
  37. #define MAX_DEATHS    64
  38.  
  39. struct {
  40.     pid_t pid;
  41.     void *data;
  42.     void (*handler)(void*);
  43. } DeadHandlers[MAX_DEATHS];
  44.  
  45.  
  46. static pid_t DeadChildren[MAX_DEATHS];
  47. static int DeadChildrenCount = 0;
  48.  
  49. void
  50. wAbort(Bool foo)
  51. {
  52.     exit(1);
  53. }
  54.  
  55.  
  56. static BOOL
  57. stringCompareHook(proplist_t pl1, proplist_t pl2)
  58. {
  59.     char *str1, *str2;
  60.  
  61.     str1 = PLGetString(pl1);
  62.     str2 = PLGetString(pl2);
  63.  
  64.     if (strcasecmp(str1, str2)==0)
  65.       return YES;
  66.     else
  67.       return NO;
  68. }
  69.  
  70.  
  71. static void
  72. print_help(char *progname)
  73. {
  74.     printf(_("usage: %s [options]\n"), progname);
  75.     puts(_("options:"));
  76.     puts(_(" -display <display>    display to be used"));
  77.     puts(_(" --version        print version number and exit"));
  78.     puts(_(" --help        print this message and exit"));
  79. }
  80.  
  81.  
  82. #if 0
  83. static RETSIGTYPE
  84. handleDeadChild(int sig)
  85. {
  86.     pid_t pid;
  87.     int status;
  88.     
  89.     pid = waitpid(-1, &status, WNOHANG);
  90.     if (pid > 0) {
  91.     DeadChildren[DeadChildrenCount++] = pid;
  92.     }
  93. }
  94. #endif
  95.  
  96. void
  97. AddDeadChildHandler(pid_t pid, void (*handler)(void*), void *data)
  98. {
  99.     int i;
  100.  
  101.     for (i = 0; i < MAX_DEATHS; i++) {
  102.     if (DeadHandlers[i].pid == 0) {
  103.         DeadHandlers[i].pid = pid;
  104.         DeadHandlers[i].handler = handler;
  105.         DeadHandlers[i].data = data;
  106.         break;
  107.     }
  108.     }
  109.     assert(i!=MAX_DEATHS);
  110. }
  111.  
  112.  
  113. int 
  114. main(int argc, char **argv)
  115. {
  116.     Display *dpy;
  117.     WMScreen *scr;
  118.     char *locale;
  119.     int i;
  120.     char *display_name="";
  121.  
  122.     wsetabort(wAbort);
  123.     
  124.     memset(DeadHandlers, 0, sizeof(DeadHandlers));
  125.     
  126.     WMInitializeApplication("WPrefs", &argc, argv);
  127.     
  128.     if (argc>1) {
  129.     for (i=1; i<argc; i++) {
  130.         if (strcmp(argv[i], "-version")==0
  131.         || strcmp(argv[i], "--version")==0) {
  132.         printf("WPrefs (Window Maker) %s\n", WVERSION);
  133.         exit(0);
  134.         } else if (strcmp(argv[i], "-display")==0) {
  135.         i++;
  136.         if (i>=argc) {
  137.             wwarning(_("too few arguments for %s"), argv[i-1]);
  138.             exit(0);
  139.         }
  140.         display_name = argv[i];
  141.         } else {
  142.         print_help(argv[0]);
  143.         exit(0);
  144.         }
  145.     }
  146.     }
  147.  
  148.     locale = getenv("LANG");
  149.     setlocale(LC_ALL, "");
  150.  
  151. #ifdef I18N
  152.     if (getenv("NLSPATH"))
  153.     bindtextdomain("WPrefs", getenv("NLSPATH"));
  154.     else
  155.     bindtextdomain("WPrefs", LOCALEDIR);
  156.     textdomain("WPrefs");
  157.  
  158.     if (!XSupportsLocale()) {
  159.     wwarning(_("X server does not support locale"));
  160.     }
  161.     if (XSetLocaleModifiers("") == NULL) {
  162.      wwarning(_("cannot set locale modifiers"));
  163.     }
  164. #endif
  165.  
  166.     dpy = XOpenDisplay(display_name);
  167.     if (!dpy) {
  168.     wfatal(_("could not open display %s"), XDisplayName(display_name));
  169.     exit(0);
  170.     }
  171. #if 0
  172.     XSynchronize(dpy, 1);
  173. #endif
  174.     scr = WMCreateScreen(dpy, DefaultScreen(dpy));
  175.     if (!scr) {
  176.     wfatal(_("could not initialize application"));
  177.     exit(0);
  178.     }
  179.  
  180.     PLSetStringCmpHook(stringCompareHook);
  181.  
  182.     Initialize(scr);
  183.  
  184.     while (1) {
  185.     XEvent event;
  186.  
  187.     WMNextEvent(dpy, &event);
  188.  
  189.     while (DeadChildrenCount-- > 0) {
  190.         int i;
  191.         
  192.         for (i=0; i<MAX_DEATHS; i++) {
  193.         if (DeadChildren[i] == DeadHandlers[i].pid) {
  194.             (*DeadHandlers[i].handler)(DeadHandlers[i].data);
  195.             DeadHandlers[i].pid = 0;
  196.         }
  197.         }
  198.     }
  199.  
  200.     WMHandleEvent(&event);
  201.     }
  202. }
  203.